package beanstao.util.collections;

/**
 * 一个成对值的类型。两个值之间的等级是相等的，不是键值的关系。
 * 
 * @author beanstao@google.com 
 * @param <L>
 * @param <R>
 */
public class Pair<L, R>
{
	public static <L, R> Pair<L, R> ME(L left, R right)
	{
		return new Pair<L, R>(left, right);
	}

	public Pair(L left, R right)
	{
		super();
		this.left = left;
		this.right = right;
	}

	protected L left;

	public L getLeft()
	{
		return this.left;
	}

	public void setLeft(L left)
	{
		this.left = left;
	}

	public R getRight()
	{
		return this.right;
	}

	public void setRight(R right)
	{
		this.right = right;
	}

	protected R right;

	@Override
	public int hashCode()
	{
		final int prime = 31;
		int result = 1;
		result = prime * result + ((left == null) ? 0 : left.hashCode());
		result = prime * result + ((right == null) ? 0 : right.hashCode());
		return result;
	}

	@SuppressWarnings("rawtypes")
	@Override
	public boolean equals(Object obj)
	{
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (this.getClass() != obj.getClass())
			return false;
		Pair other = (Pair) obj;
		if (left == null)
		{
			if (other.left != null)
				return false;
		}
		else if (!left.equals(other.left))
			return false;
		if (right == null)
		{
			if (other.right != null)
				return false;
		}
		else if (!right.equals(other.right))
			return false;
		return true;
	}

	@Override
	public String toString()
	{
		StringBuilder builder = new StringBuilder();
		builder.append("Pair [left=").append(left).append(", right=").append(right).append("]");
		return builder.toString();
	}
}
